
import { DependencyContainer, ROOT, Request } from '@sker/core'
import { dirname, join } from 'path'
import { z } from 'zod'
import { ensureDirSync, writeFileSync } from 'fs-extra'
export default (injector: DependencyContainer) => {
    const root = injector.resolve(ROOT)
    const req = injector.resolve(Request)
    const schema = z.object({
        name: z.string(),
        data: z.any()
    })
    const body = schema.parse(req.body)
    const jsonFile = join(`${root}`, 'data', 'plugins', `${body.name}.json`)
    ensureDirSync(dirname(jsonFile))
    writeFileSync(jsonFile, JSON.stringify(body.data, null, 2))
    return body;
}
